// You need to add 1 line of code at each of the 3 locations
// identified by embedded comments
package infotool;

import java.util.*;

public class InfoModel {

    // model data
    private String message = "welcome to mvc";
    private String weather = "Sunny";

    // model listener management data structures
    private ArrayList<InfoView> listeners = new ArrayList<InfoView>(10);
    
    public InfoModel() {
        System.out.println("Model: InfoModel()");
    }
    
    // state query methods
    public String getMessage() {
        System.out.println("Model: getMessage() ");
        return message;
    }
    public String getWeather() {
        System.out.println("Model: getWeather() ");
        return weather;
    }
    
    // state change methods
    public void setMessage(String msg) {
        System.out.println("Model: setMessage() ");
        message = msg;
        //** 1 students action required: There is a missing line of code
        //**   Hint It should inform all views that the model has changed
        //**   Another hint - call the fireModelChangeEvent and pass
        //**   it the attribute message.
        fireModelChangeEvent(msg);
    }
    
    public void setWeather(String wth) {
        System.out.println("Model: setWeather() ");
        weather = wth;
        //** 1 students action required: There is a missing line of code
        //**   Hint It should inform all views that the model has changed
        //**   Another hint - call the fireModelChangeEvent and pass
        //**   it the attribute weather.
        fireModelChangeEvent(wth);
    }
    
    // listener registration method
    public void addModelChangeListener(InfoView view) {
        System.out.println("Model: addModelChangeListener(view) ");
        listeners.add(view);
    }
    
    // private methods
    private void fireModelChangeEvent(Object o) {
        for (InfoView v: listeners) {
            System.out.println("Model: fireModelChangeEvent() - for loop");
            //** students action required: Fill missing line of code
            //** 1 Inform the View object v that the model has changed
            //** Hint - Call the processModelChange method on the object v
            //** and pass it the input parameter variable o.
            v.processModelChange(o);
        }
    }
}
